<?php


namespace app\controller;


//use think\Controller;
//
//class Rely extends Controller
//{
//    public function index(){
//        return $this->request->param('name');
//    }
//}

//use think\Request;
//
//class Rely{
//    public function index(Request $request){
//        //如果使用依赖注入的方式，跨域将变量作为对象的属性进行调用
//        echo $request->name;
//        return $request->param('name');
//    }
//}

//use think\Request;
//
//class Rely
//{
//    protected $request;
//    public function  __construct(Request $request)
//    {
//        $this->request = $request;
//    }
//    public function index(){
//        return $this->request->param('name');
//    }
//
use think\facade\Request;
use think\facade\Url;


class Rely{
    public function index(){
        //return Request::param('name');
        //return Request::url(true);

        //return Request::baseFile(true);
        //return Request::root(true);
        dump(Request::has('id','get'));
        dump(Request::has('name','post'));

        //param()变量方法是自动识别 GET POST 等的当前请求 推荐使用
        dump(Request::param('id',1)); //获取请求为id值，过滤
        dump(Request::param());//获取所有请求的变量，过滤
        dump(Request::param(false));//获取所有请求的变量，不包含上传变量，不过滤
        dump(Request::param(true));//获取所有请求的变量，包含上传变量，过滤


        dump(input('?get.key'));
        dump(input('param.id'));
        echo "<hr>";

        dump(Request::isAjax());
        //return Request::method();
        dump(Request::method(true)); //获取原始请求

        //dump(Request::isGet());
        //dump(Request::isPost(());
        //dump(Request::isPUT());
        echo "<hr>";
        dump(Request::header());
    }
    public function edit($id){
        dump(Request::param('id'));
        dump(Request::get('id'));  //获取不到
        dump(Request::route('id'));
    }
    public function url(){
        //先使用Url:build()方法获取当前的url路径
        //如果地址栏用后缀访问成功后，可以使用Request::ext()方法得到当前的伪静态
       return Url::build().','.Request::ext();
    }
    public function get($id,$name){
        return 'get:'.$id.$name;
    }
    public function res(){
        $data = 'HELLO ghj';
        //return response($data,201);
        return response($data)->code(202)->header(['Cathe-control'=>'no-cache,must-revalidate']);
    }
    public function rdc(){
        //return redirect('https://www.baidu.com');
        //
        //站内重定向 直接输入路由地址或相对地址 ，需要用顶级域名，二级会出错
        //return redirect('edit/5');
        //return redirect('/address/details/5');

        //也可以通过params()方法传递数组参数建值的方式进行跳转
        return redirect('/address/details')->params(['id'=>5]);
        return redirect('/address/details',['id'=>5]);
    }
    public function image(){
        return download('12.jpg','ghj.jpg');
    }
    public function text(){
        $data ="郭浩佳是大帅哥!";
        return download($data,'text.txt',true);
    }
}
//
//class Rely{
//    public function index(){
//        return request()->param('name');
//    }
//}